home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / src / X11 / seyon / MultiList.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-03  |  54.4 KB  |  1,771 lines

  1. /****************************************************************************
  2.  
  3.     MultiList.c
  4.  
  5.     This file contains the implementation of the Picasso List
  6.     widget.  Its functionality is intended to be similar to
  7.     The Athena List widget, with some extra features added.
  8.  
  9.     This code is loosely based on the Athena List source which
  10.     is why the MIT copyright notice appears below.
  11.  
  12.     The code was changed substantially in V3.4 to change the
  13.     action/callback interface which was unnecessarily ugly.  Code
  14.     using some features of the old interface may need to be changed.
  15.     Hope the changes don't make people's lives too miserable.
  16.  
  17.  ****************************************************************************/
  18.  
  19. /*
  20.  * Author:
  21.  *     Brian Totty
  22.  *     Department of Computer Science
  23.  *     University Of Illinois at Urbana-Champaign
  24.  *    1304 West Springfield Avenue
  25.  *     Urbana, IL 61801
  26.  * 
  27.  *     totty@cs.uiuc.edu
  28.  *     
  29.  */ 
  30.  
  31. /*
  32.  * Copyright 1989 Massachusetts Institute of Technology
  33.  *
  34.  * Permission to use, copy, modify, distribute, and sell this software and its
  35.  * documentation for any purpose is hereby granted without fee, provided that
  36.  * the above copyright notice appear in all copies and that both that
  37.  * copyright notice and this permission notice appear in supporting
  38.  * documentation, and that the name of M.I.T. not be used in advertising or
  39.  * publicity pertaining to distribution of the software without specific,
  40.  * written prior permission.  M.I.T. makes no representations about the
  41.  * suitability of this software for any purpose.  It is provided "as is"
  42.  * without express or implied warranty.
  43.  *
  44.  * M.I.T. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
  45.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL M.I.T.
  46.  * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  47.  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  48.  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 
  49.  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  50.  *
  51.  * Original Athena Author:  Chris D. Peterson, MIT X Consortium
  52.  */
  53.  
  54. #include <stdio.h>
  55. #include <ctype.h>
  56.  
  57. #include <X11/IntrinsicP.h>
  58. #include <X11/StringDefs.h>
  59.  
  60. #include "MultiListP.h"
  61.  
  62. /*===========================================================================*
  63.  
  64.           D E C L A R A T I O N S    A N D    D E F I N I T I O N S
  65.  
  66.  *===========================================================================*/
  67.  
  68. Pixmap XmuCreateStippledPixmap();
  69. extern void XawInitializeWidgetSet();
  70.  
  71. #define    SUPERCLASS    &(simpleClassRec)
  72.  
  73. #define    FontAscent(f)    ((f)->max_bounds.ascent)
  74. #define    FontDescent(f)    ((f)->max_bounds.descent)
  75. #define    FontH(f)    (FontAscent(f) + FontDescent(f) + 2)
  76. #define    FontW(f,s)    (XTextWidth(f,s,strlen(s)) + 1)
  77. #define    FontMaxCharW(f)    ((f)->max_bounds.rbearing-(f)->min_bounds.lbearing+1)
  78.  
  79. #ifndef abs
  80. #define abs(a)            ((a) < 0 ? -(a) : (a))
  81. #endif
  82.  
  83. #define max(a,b)        ((a) > (b) ? (a) : (b))
  84. #define min(a,b)        ((a) < (b) ? (a) : (b))
  85. #define XtStrlen(s)        ((s) ? strlen(s) : 0)
  86.  
  87. #define    TypeAlloc(t,n)        (t *)XtMalloc(sizeof(t) * n)
  88. #define    StrCopy(s)        strcpy(TypeAlloc(char,strlen(s)+1),s)
  89. #define    StrCopyRetLength(s,lp)    strcpy(TypeAlloc(char,(*lp=(strlen(s)+1))),s)
  90.  
  91. #define CoreFieldOffset(f)    XtOffset(Widget,core.f)
  92. #define    SimpleFieldOffset(f)    XtOffset(XfwfMultiListWidget,simple.f)
  93. #define MultiListFieldOffset(f)    XtOffset(XfwfMultiListWidget,multiList.f)
  94.  
  95. /*===========================================================================*
  96.  
  97.         I N T E R N A L    P R O C E D U R E    D E C L A R A T I O N S
  98.  
  99.  *===========================================================================*/
  100.  
  101. #if (!NeedFunctionPrototypes)
  102.  
  103. static void            Initialize();
  104. static void            Redisplay();
  105. static XtGeometryResult        PreferredGeometry();
  106. static void            Resize();
  107. static Boolean            SetValues();
  108.  
  109. static void            DestroyOldData();
  110. static void            InitializeNewData();
  111. static void            CreateNewGCs();
  112.  
  113. static void            RecalcCoords();
  114. static void            NegotiateSizeChange();
  115. static Boolean            Layout();
  116.  
  117. static void            RedrawAll();
  118. static void            RedrawItem();
  119. static void            RedrawRowColumn();
  120.  
  121. static void            PixelToRowColumn();
  122. static void            RowColumnToPixels();
  123. static Boolean            RowColumnToItem();
  124. static Boolean            ItemToRowColumn();
  125.  
  126. static void            Select();
  127. static void            Unselect();
  128. static void            Toggle();
  129. static void            Extend();
  130. static void            Notify();
  131.  
  132. #else
  133.  
  134. static void        Initialize(Widget request, Widget new);
  135. static void         Redisplay(XfwfMultiListWidget mlw,
  136.                 XEvent *event, Region rectangle_union);
  137. static XtGeometryResult PreferredGeometry(XfwfMultiListWidget mlw,
  138.                 XtWidgetGeometry *parent_idea,
  139.                 XtWidgetGeometry *our_idea);
  140. static void        Resize(XfwfMultiListWidget mlw);
  141. static Boolean        SetValues(XfwfMultiListWidget cpl,
  142.                 XfwfMultiListWidget rpl,
  143.             XfwfMultiListWidget npl);
  144. static void        DestroyOldData(XfwfMultiListWidget mlw);
  145. static void        InitializeNewData(XfwfMultiListWidget mlw);
  146. static void        CreateNewGCs(XfwfMultiListWidget mlw);
  147. static void        RecalcCoords(XfwfMultiListWidget mlw,
  148.                 Boolean width_changeable,
  149.                 Boolean height_changeable);
  150. static void        NegotiateSizeChange(XfwfMultiListWidget mlw,
  151.                 Dimension width, Dimension height);
  152. static Boolean        Layout(XfwfMultiListWidget mlw,
  153.                 Boolean w_changeable, Boolean h_changeable,
  154.                 Dimension *w_ptr, Dimension *h_ptr);
  155. static void        RedrawAll(XfwfMultiListWidget mlw);
  156. static void        RedrawItem(XfwfMultiListWidget mlw, int item_index);
  157. static void        RedrawRowColumn(XfwfMultiListWidget mlw,
  158.                 int row, int column);
  159. static void        PixelToRowColumn(XfwfMultiListWidget mlw,
  160.                 int x, int y, int *row_ptr, int *column_ptr);
  161. static void        RowColumnToPixels(XfwfMultiListWidget mlw,
  162.                 int row, int col, int *x_ptr, int *y_ptr,
  163.                 int *w_ptr, int *h_ptr);
  164. static Boolean        RowColumnToItem(XfwfMultiListWidget mlw,
  165.                 int row, int column, int *item_ptr);
  166. static Boolean        ItemToRowColumn(XfwfMultiListWidget mlw,
  167.                 int item_index, int *row_ptr, int *column_ptr);
  168. static void        Select(XfwfMultiListWidget mlw, XEvent *event,
  169.                 String *params, Cardinal *num_params);
  170. static void        Unselect(XfwfMultiListWidget mlw, XEvent *event,
  171.                 String *params, Cardinal *num_params);
  172. static void        Toggle(XfwfMultiListWidget mlw, XEvent *event,
  173.                 String *params, Cardinal *num_params);
  174. static void        Extend(XfwfMultiListWidget mlw, XEvent *event,
  175.                 String *params, Cardinal *num_params);
  176. static void        Notify(XfwfMultiListWidget mlw, XEvent *event,
  177.                 String *params, Cardinal *num_params);
  178. #endif
  179.  
  180. /*===========================================================================*
  181.  
  182.               R E S O U R C E    I N I T I A L I Z A T I O N
  183.  
  184.  *===========================================================================*/
  185.  
  186. static XtResource resources[] =
  187. {
  188.     {XtNwidth, XtCWidth, XtRDimension, sizeof(Dimension),
  189.         CoreFieldOffset(width), XtRString, "0"},
  190.     {XtNheight, XtCHeight, XtRDimension, sizeof(Dimension),
  191.         CoreFieldOffset(height), XtRString, "0"},
  192.     {XtNbackground, XtCBackground, XtRPixel, sizeof(Pixel),
  193.         CoreFieldOffset(background_pixel),XtRString,"XtDefaultBackground"},
  194.  
  195.     {XtNcursor, XtCCursor, XtRCursor, sizeof(Cursor),
  196.         SimpleFieldOffset(cursor), XtRString, "left_ptr"},
  197.  
  198.     {XtNforeground, XtCForeground, XtRPixel, sizeof(Pixel),
  199.         MultiListFieldOffset(foreground), XtRString,"XtDefaultForeground"},
  200.     {XtNhighlightForeground, XtCHForeground, XtRPixel, sizeof(Pixel),
  201.         MultiListFieldOffset(highlight_fg), XtRString, "XtDefaultBackground"},
  202.     {XtNhighlightBackground, XtCHBackground, XtRPixel, sizeof(Pixel),
  203.         MultiListFieldOffset(highlight_bg), XtRString, "XtDefaultForeground"},
  204.     {XtNcolumnSpacing, XtCSpacing, XtRDimension, sizeof(Dimension),
  205.         MultiListFieldOffset(column_space), XtRImmediate, (caddr_t)8},
  206.     {XtNrowSpacing, XtCSpacing, XtRDimension, sizeof(Dimension),
  207.         MultiListFieldOffset(row_space), XtRImmediate, (caddr_t)0},
  208.     {XtNdefaultColumns, XtCColumns, XtRInt,  sizeof(int),
  209.         MultiListFieldOffset(default_cols), XtRImmediate, (caddr_t)1},
  210.     {XtNforceColumns, XtCColumns, XtRBoolean, sizeof(Boolean),
  211.         MultiListFieldOffset(force_cols), XtRString, (caddr_t) "False"},
  212.     {XtNpasteBuffer, XtCBoolean, XtRBoolean, sizeof(Boolean),
  213.         MultiListFieldOffset(paste), XtRString, (caddr_t) "False"},
  214.     {XtNverticalList, XtCBoolean, XtRBoolean,  sizeof(Boolean),
  215.         MultiListFieldOffset(row_major), XtRString, (caddr_t) "False"},
  216.     {XtNlongest, XtCLongest, XtRInt,  sizeof(int),
  217.         MultiListFieldOffset(longest), XtRImmediate, (caddr_t)0},
  218.     {XtNnumberStrings, XtCNumberStrings, XtRInt,  sizeof(int),
  219.         MultiListFieldOffset(nitems), XtRImmediate, (caddr_t)0},
  220.     {XtNfont,  XtCFont, XtRFontStruct, sizeof(XFontStruct *),
  221.         MultiListFieldOffset(font),XtRString, "XtDefaultFont"},
  222.     {XtNlist, XtCList, XtRPointer, sizeof(char **),
  223.         MultiListFieldOffset(list), XtRString, NULL},
  224.     {XtNsensitiveArray, XtCList, XtRPointer, sizeof(Boolean *),
  225.         MultiListFieldOffset(sensitive_array), XtRString, NULL},
  226.     {XtNcallback, XtCCallback, XtRCallback, sizeof(caddr_t),
  227.         MultiListFieldOffset(callback), XtRCallback, NULL},
  228.     {XtNmaxSelectable, XtCValue, XtRInt, sizeof(int),
  229.         MultiListFieldOffset(max_selectable), XtRImmediate, (caddr_t) 1},
  230.  
  231.     {XtNshadeSurplus, XtCBoolean, XtRBoolean, sizeof(Boolean),
  232.         MultiListFieldOffset(shade_surplus), XtRString, "True"},
  233.  
  234.     {XtNcolumnWidth, XtCValue, XtRDimension, sizeof(Dimension),
  235.         MultiListFieldOffset(col_width), XtRImmediate, (caddr_t)0},
  236.     {XtNrowHeight, XtCValue, XtRDimension, sizeof(Dimension),
  237.         MultiListFieldOffset(row_height), XtRImmediate, (caddr_t)0},
  238. };
  239.  
  240. /*===========================================================================*
  241.  
  242.         A C T I O N    A N D    T R A N S L A T I O N    T A B L E S
  243.  
  244.  *===========================================================================*/
  245.  
  246.  
  247. static char defaultTranslations[] =
  248. "    Shift <Btn1Down>:            Toggle()\n\
  249.     Ctrl <Btn1Down>:            Unselect()\n\
  250.     <Btn1Down>:                Select()\n\
  251.     Button1 <Btn1Motion>:            Extend()\n\
  252.     <Btn1Up>:                Notify()";
  253.  
  254. static XtActionsRec actions[] =
  255. {
  256.     {"Select",                (XtActionProc)Select},
  257.     {"Unselect",                (XtActionProc)Unselect},
  258.     {"Toggle",                (XtActionProc)Toggle},
  259.     {"Extend",                (XtActionProc)Extend},
  260.     {"Notify",                (XtActionProc)Notify},
  261.     {NULL,                    (XtActionProc)NULL}
  262. };
  263.  
  264. /*===========================================================================*
  265.  
  266.                     C L A S S    A L L O C A T I O N
  267.  
  268.  *===========================================================================*/
  269.  
  270. XfwfMultiListClassRec xfwfMultiListClassRec =
  271. {
  272.     {
  273.         /* superclass        */    (WidgetClass)SUPERCLASS,
  274.         /* class_name        */    "XfwfMultiList",
  275.         /* widget_size        */    sizeof(XfwfMultiListRec),
  276.         /* class_initialize    */    NULL,
  277.         /* class_part_initialize*/    NULL,
  278.         /* class_inited        */    FALSE,
  279.         /* initialize        */    (XtInitProc)Initialize,
  280.         /* initialize_hook    */    NULL,
  281.         /* realize        */    XtInheritRealize,
  282.         /* actions        */    actions,
  283.         /* num_actions        */    XtNumber(actions),
  284.         /* resources        */    resources,
  285.         /* resource_count    */    XtNumber(resources),
  286.         /* xrm_class        */    NULLQUARK,
  287.         /* compress_motion    */    TRUE,
  288.         /* compress_exposure    */    FALSE,
  289.         /* compress_enterleave    */    TRUE,
  290.         /* visible_interest    */    FALSE,
  291.         /* destroy        */    NULL,
  292.         /* resize        */    (XtWidgetProc)Resize,
  293.         /* expose        */    (XtExposeProc)Redisplay,
  294.         /* set_values        */    (XtSetValuesFunc)SetValues,
  295.         /* set_values_hook    */    NULL,
  296.         /* set_values_almost    */    XtInheritSetValuesAlmost,
  297.         /* get_values_hook    */    NULL,
  298.         /* accept_focus        */    NULL,
  299.         /* version        */    XtVersion,
  300.         /* callback_private    */    NULL,
  301.         /* tm_table        */    defaultTranslations,
  302.         /* query_geometry       */    (XtGeometryHandler)
  303.                             PreferredGeometry,
  304.         /* display_accelerator  */    XtInheritDisplayAccelerator,
  305.         /* extension            */    NULL
  306.     }, /* Core Part */
  307.     {
  308.         /* change_sensitive     */    XtInheritChangeSensitive
  309.     }
  310. };
  311.  
  312. WidgetClass xfwfMultiListWidgetClass = (WidgetClass)&xfwfMultiListClassRec;
  313.  
  314. /*===========================================================================*
  315.  
  316.                        T O O L K I T    M E T H O D S
  317.  
  318.  *===========================================================================*/
  319.  
  320. /*---------------------------------------------------------------------------*
  321.  
  322.     Initialize()
  323.  
  324.     This procedure is called by the X toolkit to initialize
  325.     the widget instance.  The hook to this routine is in the
  326.     initialize part of the core part of the class.
  327.  
  328.  *---------------------------------------------------------------------------*/
  329.  
  330. /* ARGSUSED */
  331. static void Initialize(request,new)
  332. Widget request,new;
  333. {
  334.     XfwfMultiListWidget mlw;
  335.  
  336.     mlw = (XfwfMultiListWidget)new;
  337.     CreateNewGCs(mlw);
  338.     InitializeNewData(mlw);
  339.     RecalcCoords(mlw,(MultiListWidth(mlw) == 0),
  340.              (MultiListHeight(mlw) == 0));
  341. } /* Initialize */
  342.  
  343.  
  344. /*---------------------------------------------------------------------------*
  345.  
  346.     Redisplay(mlw,event,rectangle_union)
  347.  
  348.     This routine redraws the MultiList widget <mlw> based on the exposure
  349.     region requested in <event>.
  350.  
  351.  *---------------------------------------------------------------------------*/
  352.  
  353. /* ARGSUSED */
  354. static void Redisplay(mlw,event,rectangle_union)
  355. XfwfMultiListWidget mlw;
  356. XEvent *event;
  357. Region rectangle_union;
  358. {
  359.     GC shade_gc;
  360.     int i,x1,y1,w,h,x2,y2,row,col,ul_row,ul_col,lr_row,lr_col;
  361.  
  362.     if (MultiListShadeSurplus(mlw))
  363.         shade_gc = MultiListGrayGC(mlw);
  364.         else
  365.         shade_gc = MultiListEraseGC(mlw);
  366.     if (event == NULL)
  367.     {
  368.         XFillRectangle(XtDisplay(mlw),XtWindow(mlw),shade_gc,0,0,
  369.                    MultiListWidth(mlw),MultiListHeight(mlw));
  370.         for (i = 0; i < MultiListNumItems(mlw); i++) RedrawItem(mlw,i);
  371.     }
  372.         else
  373.     {
  374.         x1 = event->xexpose.x;
  375.         y1 = event->xexpose.y;
  376.         w = event->xexpose.width;
  377.         h = event->xexpose.height;
  378.         x2 = x1 + w;
  379.         y2 = y1 + h;
  380.         XFillRectangle(XtDisplay(mlw),XtWindow(mlw),
  381.                    shade_gc,x1,y1,w,h);
  382.         PixelToRowColumn(mlw,x1,y1,&ul_row,&ul_col);
  383.         PixelToRowColumn(mlw,x2,y2,&lr_row,&lr_col);
  384.         lr_row = min(lr_row,MultiListNumRows(mlw) - 1);
  385.         lr_col = min(lr_col,MultiListNumCols(mlw) - 1);
  386.         for (col = ul_col; col <= lr_col; col++)
  387.         {
  388.             for (row = ul_row; row <= lr_row; row++)
  389.             {
  390.                 RedrawRowColumn(mlw,row,col);
  391.             }
  392.         }
  393.     }
  394. } /* End Redisplay */
  395.  
  396.  
  397. /*---------------------------------------------------------------------------*
  398.  
  399.     PreferredGeometry(mlw,parent_idea,our_idea)
  400.  
  401.     This routine is called by the parent to tell us about the
  402.     parent's idea of our width and/or height.  We then suggest
  403.     our preference through <our_idea> and return the information
  404.     to the parent.
  405.  
  406.  *---------------------------------------------------------------------------*/
  407.  
  408. static XtGeometryResult PreferredGeometry(mlw,parent_idea,our_idea)
  409. XfwfMultiListWidget mlw;
  410. XtWidgetGeometry *parent_idea,*our_idea;
  411. {
  412.     Dimension nw,nh;
  413.     Boolean parent_wants_w,parent_wants_h,we_changed_size;
  414.     
  415.     parent_wants_w = (parent_idea->request_mode) & CWWidth;
  416.     parent_wants_h = (parent_idea->request_mode) & CWHeight;
  417.  
  418.     if (parent_wants_w)
  419.         nw = parent_idea->width;
  420.         else
  421.         nw = MultiListWidth(mlw);
  422.  
  423.     if (parent_wants_h)
  424.         nh = parent_idea->height;
  425.         else
  426.         nh = MultiListHeight(mlw);
  427.  
  428.     our_idea->request_mode = 0;
  429.     if (!parent_wants_w && !parent_wants_h) return(XtGeometryYes);
  430.  
  431.     we_changed_size = Layout(mlw,!parent_wants_w,!parent_wants_h,&nw,&nh);
  432.     our_idea->request_mode |= (CWWidth | CWHeight);
  433.     our_idea->width = nw;
  434.     our_idea->height = nh;
  435.  
  436.     if (we_changed_size)
  437.         return(XtGeometryAlmost);
  438.         else
  439.         return(XtGeometryYes);
  440. } /* End PreferredGeometry */
  441.  
  442.  
  443. /*---------------------------------------------------------------------------*
  444.  
  445.     Resize(mlw)
  446.  
  447.     This function is called when the widget is being resized.  It
  448.     recalculates the layout of the widget.
  449.  
  450.  *---------------------------------------------------------------------------*/
  451.  
  452. static void Resize(mlw)
  453. XfwfMultiListWidget mlw;
  454. {
  455.     Dimension width,height;
  456.  
  457.     width = MultiListWidth(mlw);
  458.     height = MultiListHeight(mlw);
  459.     Layout(mlw,False,False,&width,&height);
  460. } /* End Resize */
  461.  
  462.  
  463. /*---------------------------------------------------------------------------*
  464.  
  465.     SetValues(cpl,rpl,npl)
  466.  
  467.     This routine is called when the user is changing resources.  <cpl>
  468.     is the current widget before the user's changes have been instituted.
  469.     <rpl> includes the original changes as requested by the user.  <npl>
  470.     is the new resulting widget with the requested changes and with all
  471.     superclass changes already made.
  472.  
  473.  *---------------------------------------------------------------------------*/
  474.  
  475. /*ARGSUSED*/
  476. static Boolean SetValues(cpl,rpl,npl)
  477. XfwfMultiListWidget cpl,rpl,npl;
  478. {
  479.     Boolean redraw,recalc;
  480.  
  481.     redraw = False;
  482.     recalc = False;
  483.  
  484.         /* Graphic Context Changes */
  485.  
  486.     if ((MultiListFG(cpl) != MultiListFG(npl)) ||
  487.         (MultiListBG(cpl) != MultiListBG(npl)) ||
  488.         (MultiListHighlightFG(cpl) != MultiListHighlightFG(npl)) ||
  489.         (MultiListHighlightBG(cpl) != MultiListHighlightBG(npl)) ||
  490.         (MultiListFont(cpl) != MultiListFont(npl)))
  491.     {
  492.         XtDestroyGC(MultiListEraseGC(cpl));
  493.         XtDestroyGC(MultiListDrawGC(cpl));
  494.         XtDestroyGC(MultiListHighlightForeGC(cpl));
  495.         XtDestroyGC(MultiListHighlightBackGC(cpl));
  496.         XtDestroyGC(MultiListGrayGC(cpl));
  497.         CreateNewGCs(npl);
  498.         redraw = True;
  499.     }
  500.  
  501.         /* Changes That Require Redraw */
  502.  
  503.     if ((MultiListSensitive(cpl) != MultiListSensitive(npl)) ||
  504.         (MultiListAncesSensitive(cpl) != MultiListAncesSensitive(npl)))
  505.     {
  506.         redraw = True;
  507.     }
  508.  
  509.         /* Changes That Require Selection Changes */
  510.  
  511.     if ((MultiListMaxSelectable(cpl) != MultiListMaxSelectable(npl)))
  512.     {
  513.         XtWarning("Dynamic change to maxSelectable unimplemented");
  514.     }
  515.  
  516.         /* Changes That Require Data Initialization */
  517.  
  518.     if ((MultiListList(cpl) != MultiListList(npl)) ||
  519.         (MultiListNumItems(cpl) != MultiListNumItems(npl)) ||
  520.         (MultiListSensitiveArray(cpl) != MultiListSensitiveArray(npl)))
  521.     {
  522.         DestroyOldData(cpl);
  523.         InitializeNewData(npl);
  524.         recalc = True;
  525.         redraw = True;
  526.     }
  527.  
  528.         /* Changes That Require Recalculating Coordinates */
  529.  
  530.     if ((MultiListWidth(cpl) != MultiListWidth(npl)) ||
  531.         (MultiListHeight(cpl) != MultiListHeight(npl)) ||
  532.         (MultiListColumnSpace(cpl) != MultiListColumnSpace(npl)) ||
  533.         (MultiListRowSpace(cpl) != MultiListRowSpace(npl)) ||
  534.         (MultiListDefaultCols(cpl) != MultiListDefaultCols(npl)) ||
  535.         ((MultiListForceCols(cpl) != MultiListForceCols(npl)) &&
  536.          (MultiListNumCols(cpl) != MultiListNumCols(npl))) ||
  537.         (MultiListRowMajor(cpl) != MultiListRowMajor(npl)) ||
  538.         (MultiListFont(cpl) != MultiListFont(npl)) ||
  539.         (MultiListLongest(cpl) != MultiListLongest(npl)))
  540.     {
  541.         recalc = True;
  542.         redraw = True;
  543.     }
  544.  
  545.     if (MultiListColWidth(cpl) != MultiListColWidth(npl))
  546.     {
  547.         XtWarning("columnWidth Resource Is Read-Only");
  548.         MultiListColWidth(npl) = MultiListColWidth(cpl);
  549.     }
  550.     if (MultiListRowHeight(cpl) != MultiListRowHeight(npl))
  551.     {
  552.         XtWarning("rowHeight Resource Is Read-Only");
  553.         MultiListRowHeight(npl) = MultiListRowHeight(cpl);
  554.     }
  555.  
  556.     if (recalc)
  557.     {
  558.         RecalcCoords(npl,!MultiListWidth(npl),!MultiListHeight(npl));
  559.     }
  560.     
  561.     if (!XtIsRealized((Widget)cpl))
  562.         return(False);
  563.         else
  564.         return(redraw);
  565. } /* End SetValues */
  566.  
  567. /*===========================================================================*
  568.  
  569.                   D A T A    I N I T I A L I Z A T I O N
  570.  
  571.  *===========================================================================*/
  572.  
  573. /*---------------------------------------------------------------------------*
  574.  
  575.     DestroyOldData(mlw)
  576.  
  577.     This routine frees the internal list item array and sets the
  578.     item count to 0.  This is normally done immediately before
  579.     calling InitializeNewData() to rebuild the internal item
  580.     array from new user specified arrays.
  581.  
  582.  *---------------------------------------------------------------------------*/
  583.  
  584. static void DestroyOldData(mlw)
  585. XfwfMultiListWidget mlw;
  586. {
  587.     int i;
  588.  
  589.     if (MultiListItemArray(mlw) != NULL)    /* Free Old List */
  590.     {
  591.         for (i = 0; i < MultiListNumItems(mlw); i++)
  592.         {
  593.             XtFree(MultiListItemString(MultiListNthItem(mlw,i)));
  594.         }
  595.         XtFree((char *)MultiListItemArray(mlw));
  596.     }
  597.     if (MultiListSelArray(mlw) != NULL)
  598.         XtFree((char *)MultiListSelArray(mlw));
  599.     MultiListSelArray(mlw) = NULL;
  600.     MultiListNumSelected(mlw) = 0;
  601.     MultiListItemArray(mlw) = NULL;
  602.     MultiListNumItems(mlw) = 0;
  603. } /* End DestroyOldData */
  604.  
  605.  
  606. /*---------------------------------------------------------------------------*
  607.  
  608.     InitializeNewData(mlw)
  609.  
  610.     This routine takes a MultiList widget <mlw> and builds up new
  611.     data item tables based on the string list and the sensitivity array.
  612.     All previous data should have already been freed.  If the number
  613.     of items is 0, they will be counted, so the array must be NULL
  614.     terminated.  If the list of strings is NULL, this is treated as
  615.     a list of 0 elements.  If the sensitivity array is NULL, all
  616.     items are treated as sensitive.
  617.  
  618.     When this routine is done, the string list and sensitivity array
  619.     fields will all be set to NULL, and the widget will not reference
  620.     them again.
  621.  
  622.  *---------------------------------------------------------------------------*/
  623.  
  624. static void InitializeNewData(mlw)
  625. XfwfMultiListWidget mlw;
  626. {
  627.     int i;
  628.     XfwfMultiListItem *item;
  629.     String *string_array;
  630.  
  631.     string_array = MultiListList(mlw);
  632.     if (string_array == NULL) MultiListNumItems(mlw) = 0;
  633.  
  634.     if (MultiListNumItems(mlw) == 0)        /* Count Elements */
  635.     {
  636.         if (string_array == NULL)        /* No elements */
  637.         {
  638.             MultiListNumItems(mlw) = 0;
  639.         }
  640.             else
  641.         {
  642.             for (i = 0; string_array[i] != NULL; i++);
  643.             MultiListNumItems(mlw) = i;
  644.         }
  645.     }
  646.     if (MultiListNumItems(mlw) == 0)        /* No Items */
  647.     {
  648.         MultiListItemArray(mlw) = NULL;
  649.     }
  650.         else
  651.     {
  652.         MultiListItemArray(mlw) =
  653.             TypeAlloc(XfwfMultiListItem,MultiListNumItems(mlw));
  654.         for (i = 0; i < MultiListNumItems(mlw); i++)
  655.         {
  656.             item = MultiListNthItem(mlw,i);
  657.             if (MultiListSensitiveArray(mlw) == NULL ||
  658.                 (MultiListSensitiveArray(mlw)[i] == True))
  659.             {
  660.                 MultiListItemSensitive(item) = True;
  661.             }
  662.                 else
  663.             {
  664.                 MultiListItemSensitive(item) = False;
  665.             }
  666.             MultiListItemString(item) = StrCopy(string_array[i]);
  667.             MultiListItemHighlighted(item) = False;
  668.         }
  669.     }
  670.     if (MultiListMaxSelectable(mlw) == 0)
  671.     {
  672.         MultiListSelArray(mlw) = NULL;
  673.         MultiListNumSelected(mlw) = 0;
  674.     }
  675.         else
  676.     {
  677.         MultiListSelArray(mlw) =
  678.             TypeAlloc(int,MultiListMaxSelectable(mlw));
  679.         MultiListNumSelected(mlw) = 0;
  680.     }
  681.  
  682.     MultiListList(mlw) = NULL;
  683.     MultiListSensitiveArray(mlw) = NULL;
  684. } /* End InitializeNewData */
  685.         
  686.  
  687. /*---------------------------------------------------------------------------*
  688.  
  689.     CreateNewGCs(mlw)
  690.  
  691.     This routine takes a MultiList widget <mlw> and creates a new set of
  692.     graphic contexts for the widget based on the colors, fonts, etc.
  693.     in the widget.  Any previous GCs are assumed to have already been
  694.     destroyed.
  695.  
  696.  *---------------------------------------------------------------------------*/
  697.  
  698. static void CreateNewGCs(mlw)
  699. XfwfMultiListWidget mlw;
  700. {
  701.     XGCValues values;
  702.     unsigned int attribs;
  703.  
  704.     attribs = GCForeground | GCBackground | GCFont;
  705.     values.foreground = MultiListFG(mlw);
  706.     values.background = MultiListBG(mlw);
  707.     values.font = MultiListFont(mlw)->fid;
  708.     MultiListDrawGC(mlw) = XtGetGC((Widget)mlw,attribs,&values);
  709.  
  710.     values.foreground = MultiListBG(mlw);
  711.     MultiListEraseGC(mlw) = XtGetGC((Widget)mlw,attribs,&values);
  712.  
  713.     values.foreground = MultiListHighlightFG(mlw);
  714.     values.background = MultiListHighlightBG(mlw);
  715.     MultiListHighlightForeGC(mlw) = XtGetGC((Widget)mlw,attribs,&values);
  716.  
  717.     values.foreground = MultiListHighlightBG(mlw);
  718.     values.background = MultiListHighlightBG(mlw);
  719.     MultiListHighlightBackGC(mlw) = XtGetGC((Widget)mlw,attribs,&values);
  720.  
  721.     attribs |= GCTile | GCFillStyle;
  722.     values.foreground = MultiListFG(mlw);
  723.     values.background = MultiListBG(mlw);
  724.     values.fill_style = FillTiled;
  725.     values.tile = XmuCreateStippledPixmap(XtScreen(mlw),MultiListFG(mlw),
  726.                           MultiListBG(mlw),MultiListDepth(mlw));
  727.     MultiListGrayGC(mlw) = XtGetGC((Widget)mlw,attribs,&values);
  728. } /* End CreateNewGCs */
  729.  
  730. /*===========================================================================*
  731.  
  732.         L A Y O U T    A N D    G E O M E T R Y    M A N A G E M E N T
  733.  
  734.  *===========================================================================*/
  735.  
  736. /*---------------------------------------------------------------------------*
  737.  
  738.         RecalcCoords(mlw,width_changeable,height_changeable)
  739.  
  740.     This routine takes a MultiList widget <mlw> and recalculates
  741.     the coordinates, and item placement based on the current
  742.     width, height, and list of items.  The <width_changeable> and
  743.     <height_changeable> indicate if the width and/or height can
  744.     be arbitrarily set.
  745.  
  746.     This routine requires that the internal list data be initialized.
  747.  
  748.  *---------------------------------------------------------------------------*/
  749.  
  750. #if NeedFunctionPrototypes
  751. static void
  752. RecalcCoords(XfwfMultiListWidget mlw,
  753.          Boolean width_changeable, Boolean height_changeable)
  754. #else
  755. static void
  756. RecalcCoords(mlw,width_changeable,height_changeable)
  757. XfwfMultiListWidget mlw;
  758. Boolean width_changeable,height_changeable;
  759. #endif
  760. {
  761.     String str;
  762.     Dimension width,height;
  763.     register int i,text_width;
  764.  
  765.     width = MultiListWidth(mlw);
  766.     height = MultiListHeight(mlw);
  767.     if (MultiListNumItems(mlw) != 0 && MultiListLongest(mlw) == 0)
  768.     {
  769.         for (i = 0; i < MultiListNumItems(mlw); i++)
  770.         {
  771.             str = MultiListItemString(MultiListNthItem(mlw,i));
  772.             text_width = FontW(MultiListFont(mlw),str);
  773.             MultiListLongest(mlw) = max(MultiListLongest(mlw),
  774.                             text_width);
  775.         }
  776.     }
  777.     if (Layout(mlw,width_changeable,height_changeable,&width,&height))
  778.     {
  779.         NegotiateSizeChange(mlw,width,height);
  780.     }
  781. } /* End RecalcCoords */
  782.  
  783.  
  784. /*---------------------------------------------------------------------------*
  785.  
  786.         NegotiateSizeChange(mlw,width,height)
  787.  
  788.     This routine tries to change the MultiList widget <mlw> to have the
  789.     new size <width> by <height>.  A negotiation will takes place
  790.     to try to change the size.  The resulting size is not necessarily
  791.     the requested size.
  792.  
  793.  *---------------------------------------------------------------------------*/
  794.  
  795. #if NeedFunctionPrototypes
  796. static void
  797. NegotiateSizeChange(XfwfMultiListWidget mlw, Dimension width, Dimension height)
  798. #else
  799. static void
  800. NegotiateSizeChange(mlw,width,height)
  801. XfwfMultiListWidget mlw;
  802. Dimension width,height;
  803. #endif
  804. {
  805.     int attempt_number;
  806.     Boolean w_fixed,h_fixed;
  807.     Dimension *w_ptr,*h_ptr;
  808.     
  809.     XtWidgetGeometry request,reply;
  810.  
  811.     request.request_mode = CWWidth | CWHeight;
  812.     request.width = width;
  813.     request.height = height;
  814.     
  815.     for (attempt_number = 1; attempt_number <= 3; attempt_number++)
  816.     {
  817.         switch (XtMakeGeometryRequest((Widget)mlw,&request,&reply))
  818.         {
  819.             case XtGeometryYes:
  820.             case XtGeometryNo:
  821.             return;
  822.             case XtGeometryAlmost:
  823.             switch (attempt_number)
  824.             {
  825.                 case 1:
  826.                 w_fixed = (request.width != reply.width);
  827.                 h_fixed = (request.height != reply.height);
  828.                 w_ptr = &(reply.width);
  829.                 h_ptr = &(reply.height);
  830.                 Layout(mlw,!w_fixed,!h_fixed,w_ptr,h_ptr);
  831.                 break;
  832.                 case 2:
  833.                 w_ptr = &(reply.width);
  834.                 h_ptr = &(reply.height);
  835.                 Layout(mlw,False,False,w_ptr,h_ptr);
  836.                 break;
  837.                 case 3:
  838.                 return;
  839.             }
  840.             break;
  841.             default:
  842.             XtAppWarning(XtWidgetToApplicationContext((Widget)mlw),
  843.                 "MultiList Widget: Unknown geometry return.");
  844.             break;
  845.         }
  846.         request = reply;
  847.     }
  848. } /* End NegotiateSizeChange */
  849.  
  850.  
  851. /*---------------------------------------------------------------------------*
  852.  
  853.     Boolean Layout(mlw,w_changeable,h_changeable,w_ptr,h_ptr)
  854.  
  855.     This routine tries to generate a layout for the MultiList widget
  856.     <mlw>.  The Layout routine is free to arbitrarily set the width
  857.     or height if the corresponding variables <w_changeable> and
  858.     <h_changeable> are set True.  Otherwise the original width or
  859.     height in <w_ptr> and <h_ptr> are used as fixed values.  The
  860.     resulting new width and height are stored back through the
  861.     <w_ptr> and <h_ptr> pointers.  False is returned if no size
  862.     change was done, True is returned otherwise.
  863.  
  864.  *---------------------------------------------------------------------------*/
  865.  
  866. #if NeedFunctionPrototypes
  867. static Boolean
  868. Layout(XfwfMultiListWidget mlw, Boolean w_changeable, Boolean h_changeable,
  869.        Dimension *w_ptr, Dimension *h_ptr)
  870. #else
  871. static Boolean
  872. Layout(mlw,w_changeable,h_changeable,w_ptr,h_ptr)
  873. XfwfMultiListWidget mlw;
  874. Boolean w_changeable,h_changeable;
  875. Dimension *w_ptr,*h_ptr;
  876. #endif
  877. {
  878.     Boolean size_changed = False;
  879.  
  880.     /*
  881.      * If force columns is set, then always use the number
  882.      * of columns specified by default_cols.
  883.      */
  884.  
  885.     MultiListColWidth(mlw) = MultiListLongest(mlw) +
  886.         MultiListColumnSpace(mlw);
  887.     MultiListRowHeight(mlw) = FontH(MultiListFont(mlw)) +
  888.         MultiListRowSpace(mlw);
  889.     if (MultiListForceCols(mlw))
  890.     {
  891.         MultiListNumCols(mlw) = max(MultiListDefaultCols(mlw),1);
  892.         if (MultiListNumItems(mlw) == 0)
  893.             MultiListNumRows(mlw) = 1;
  894.             else
  895.             MultiListNumRows(mlw) = (MultiListNumItems(mlw) - 1) /
  896.                 MultiListNumCols(mlw) + 1;
  897.         if (w_changeable)
  898.         {
  899.             *w_ptr = MultiListNumCols(mlw) *
  900.                 MultiListColWidth(mlw);
  901.             size_changed = True;
  902.         }
  903.             else
  904.         {
  905.             MultiListColWidth(mlw) = *w_ptr /
  906.                 (Dimension)MultiListNumCols(mlw);
  907.         }
  908.         if (h_changeable)
  909.         {
  910.             *h_ptr = MultiListNumRows(mlw) *
  911.                 MultiListRowHeight(mlw);
  912.             size_changed = True;
  913.         }
  914.         return(size_changed);
  915.     }
  916.  
  917.     /*
  918.      * If both width and height are free to change then use
  919.      * default_cols to determine the number of columns and set
  920.      * the new width and height to just fit the window.
  921.      */
  922.  
  923.     if (w_changeable && h_changeable)
  924.     {
  925.         MultiListNumCols(mlw) = max(MultiListDefaultCols(mlw),1);
  926.         if (MultiListNumItems(mlw) == 0)
  927.             MultiListNumRows(mlw) = 1;
  928.             else
  929.             MultiListNumRows(mlw) = (MultiListNumItems(mlw) - 1) /
  930.                 MultiListNumCols(mlw) + 1;
  931.         *w_ptr = MultiListNumCols(mlw) * MultiListColWidth(mlw);
  932.         *h_ptr = MultiListNumRows(mlw) * MultiListRowHeight(mlw);
  933.         return(True);
  934.     }
  935.  
  936.     /*
  937.      * If the width is fixed then use it to determine the
  938.      * number of columns.  If the height is free to move
  939.      * (width still fixed) then resize the height of the
  940.      * widget to fit the current MultiList exactly.
  941.      */
  942.  
  943.     if (!w_changeable)
  944.     {
  945.         MultiListNumCols(mlw) = *w_ptr / MultiListColWidth(mlw);
  946.         MultiListNumCols(mlw) = max(MultiListNumCols(mlw),1);
  947.         MultiListNumRows(mlw) = (MultiListNumItems(mlw) - 1) /
  948.             MultiListNumCols(mlw) + 1;
  949.         MultiListColWidth(mlw) = *w_ptr / (Dimension)MultiListNumCols(mlw);
  950.         if (h_changeable)
  951.         {
  952.             *h_ptr = MultiListNumRows(mlw) * MultiListRowHeight(mlw);
  953.             size_changed = True;
  954.         }
  955.         return(size_changed);
  956.     }
  957.  
  958.     /*
  959.      * The last case is xfree and !yfree we use the height to
  960.      * determine the number of rows and then set the width to
  961.      * just fit the resulting number of columns.
  962.      */
  963.  
  964.     MultiListNumRows(mlw) = *h_ptr / MultiListRowHeight(mlw);
  965.     MultiListNumRows(mlw) = max(MultiListNumRows(mlw),1);
  966.     MultiListNumCols(mlw) = (MultiListNumItems(mlw) - 1) /
  967.         MultiListNumRows(mlw) + 1;
  968.     *w_ptr = MultiListNumCols(mlw) * MultiListColWidth(mlw);
  969.     return(True);
  970. } /* End Layout */
  971.  
  972. /*===========================================================================*
  973.  
  974.                     R E D R A W    R O U T I N E S
  975.  
  976.  *===========================================================================*/
  977.  
  978. /*---------------------------------------------------------------------------*
  979.  
  980.     RedrawAll(mlw)
  981.  
  982.     This routine simple calls Redisplay to redraw the entire
  983.     MultiList widget <mlw>.
  984.  
  985.  *---------------------------------------------------------------------------*/
  986.  
  987. static void RedrawAll(mlw)
  988. XfwfMultiListWidget mlw;
  989. {
  990.     Redisplay(mlw,NULL,NULL);
  991. } /* End RedrawAll */
  992.  
  993.  
  994. /*---------------------------------------------------------------------------*
  995.  
  996.     RedrawItem(mlw,item_index)
  997.  
  998.     This routine redraws the item with index <item_index> in the
  999.     MultiList widget <mlw>.  If the item number is bad, nothing is drawn.
  1000.  
  1001.  *---------------------------------------------------------------------------*/
  1002.  
  1003. static void RedrawItem(mlw,item_index)
  1004. XfwfMultiListWidget mlw;
  1005. int item_index;
  1006. {
  1007.     int row,column;
  1008.  
  1009.     if (ItemToRowColumn(mlw,item_index,&row,&column))
  1010.     {
  1011.         RedrawRowColumn(mlw,row,column);
  1012.     }
  1013. } /* End RedrawItem */
  1014.  
  1015.  
  1016. /*---------------------------------------------------------------------------*
  1017.  
  1018.     RedrawRowColumn(mlw,row,column)
  1019.  
  1020.     This routine paints the item in row/column position <row>,<column>
  1021.     on the MultiList widget <mlw>.  If the row/column coordinates are
  1022.     outside the widget, nothing is drawn.  If the position is empty,
  1023.     blank space is drawn.
  1024.  
  1025.  *---------------------------------------------------------------------------*/
  1026.  
  1027. static void RedrawRowColumn(mlw,row,column)
  1028. XfwfMultiListWidget mlw;
  1029. int row,column;
  1030. {
  1031.     GC bg_gc,fg_gc;
  1032.     XfwfMultiListItem *item;
  1033.     int ul_x,ul_y,str_x,str_y,w,h,item_index,has_item,text_h;
  1034.  
  1035.     if (!XtIsRealized((Widget)mlw)) return;
  1036.     has_item = RowColumnToItem(mlw,row,column,&item_index);
  1037.     RowColumnToPixels(mlw,row,column,&ul_x,&ul_y,&w,&h);
  1038.  
  1039.     if (has_item == False)                    /* No Item */
  1040.     {
  1041.         if (MultiListShadeSurplus(mlw))
  1042.             bg_gc = MultiListGrayGC(mlw);
  1043.             else
  1044.             bg_gc = MultiListEraseGC(mlw);
  1045.         XFillRectangle(XtDisplay(mlw),XtWindow(mlw),bg_gc,ul_x,ul_y,w,h);
  1046.     }
  1047.         else
  1048.     {
  1049.         item = MultiListNthItem(mlw,item_index);
  1050.         if ((!MultiListSensitive(mlw)) ||
  1051.             (!MultiListItemSensitive(item)))    /* Insensitive */
  1052.         {
  1053.                 if (MultiListItemHighlighted(item))    /* Selected */
  1054.             {
  1055.                 bg_gc = MultiListGrayGC(mlw);
  1056.                 fg_gc = MultiListEraseGC(mlw);
  1057.             }
  1058.                 else                /* !Selected */
  1059.             {
  1060.                 bg_gc = MultiListEraseGC(mlw);
  1061.                 fg_gc = MultiListGrayGC(mlw);
  1062.             }
  1063.         }
  1064.             else                /* Sensitive */
  1065.         {
  1066.                 if (MultiListItemHighlighted(item))    /* Selected */
  1067.             {
  1068.                 bg_gc = MultiListHighlightBackGC(mlw);
  1069.                 fg_gc = MultiListHighlightForeGC(mlw);
  1070.             }
  1071.                 else                /* !Selected */
  1072.             {
  1073.                 bg_gc = MultiListEraseGC(mlw);
  1074.                 fg_gc = MultiListDrawGC(mlw);
  1075.             }
  1076.         }
  1077.         XFillRectangle(XtDisplay(mlw),XtWindow(mlw),bg_gc,ul_x,ul_y,w,h);
  1078.  
  1079.         text_h = min(FontH(MultiListFont(mlw)) +
  1080.                  (int)MultiListRowSpace(mlw),(int)MultiListRowHeight(mlw));
  1081.         str_x = ul_x + MultiListColumnSpace(mlw) / 2;
  1082.         str_y = ul_y + FontAscent(MultiListFont(mlw)) +
  1083.             ((int)MultiListRowHeight(mlw) - text_h) / 2;
  1084.         XDrawString(XtDisplay(mlw),XtWindow(mlw),fg_gc,
  1085.                 str_x,str_y,MultiListItemString(item),
  1086.                 strlen(MultiListItemString(item)));
  1087.     }
  1088. } /* End RedrawRowColumn */
  1089.     
  1090. /*===========================================================================*
  1091.  
  1092.                I T E M    L O C A T I O N    R O U T I N E S
  1093.  
  1094.  *===========================================================================*/
  1095.  
  1096. /*---------------------------------------------------------------------------*
  1097.  
  1098.     void PixelToRowColumn(mlw,x,y,row_ptr,column_ptr)
  1099.  
  1100.     This routine takes pixel coordinates <x>, <y> and converts
  1101.     the pixel coordinate into a row/column coordinate.  This row/column
  1102.     coordinate can then easily be converted into the specific item
  1103.     in the list via the function RowColumnToItem().
  1104.  
  1105.     If the pixel lies in blank space outside of the items, the
  1106.     row & column numbers will be outside of the range of normal
  1107.     row & columns numbers, but will correspond to the row & column
  1108.     of the item, if an item was actually there.
  1109.  
  1110.  *---------------------------------------------------------------------------*/
  1111.  
  1112. static void PixelToRowColumn(mlw,x,y,row_ptr,column_ptr)
  1113. XfwfMultiListWidget mlw;
  1114. int x,y,*row_ptr,*column_ptr;
  1115. {
  1116.     *row_ptr = y / (int)MultiListRowHeight(mlw);
  1117.     *column_ptr = x / (int)MultiListColWidth(mlw);
  1118. } /* End PixelToRowColumn */
  1119.  
  1120. /*---------------------------------------------------------------------------*
  1121.  
  1122.     void RowColumnToPixels(mlw,row,col,x_ptr,y_ptr,w_ptr,h_ptr)
  1123.  
  1124.     This routine takes a row/column coordinate <row>,<col> and
  1125.     converts it into the bounding pixel rectangle which is returned.
  1126.  
  1127.  *---------------------------------------------------------------------------*/
  1128.  
  1129. static void RowColumnToPixels(mlw,row,col,x_ptr,y_ptr,w_ptr,h_ptr)
  1130. XfwfMultiListWidget mlw;
  1131. int row,col,*x_ptr,*y_ptr,*w_ptr,*h_ptr;
  1132. {
  1133.     *x_ptr = col * MultiListColWidth(mlw);
  1134.     *y_ptr = row * MultiListRowHeight(mlw);
  1135.     *w_ptr = MultiListColWidth(mlw);
  1136.     *h_ptr = MultiListRowHeight(mlw);
  1137. } /* End RowColumnToPixels */
  1138.  
  1139. /*---------------------------------------------------------------------------*
  1140.  
  1141.     Boolean RowColumnToItem(mlw,row,column,item_ptr)
  1142.  
  1143.     This routine takes a row number <row> and a column number <column>
  1144.     and tries to resolve this row and column into the index of the
  1145.     item in this position of the MultiList widget <mlw>.  The resulting
  1146.     item index is placed through <item_ptr>.  If there is no item at
  1147.     this location, False is returned, else True is returned.
  1148.  
  1149.  *---------------------------------------------------------------------------*/
  1150.  
  1151. static Boolean RowColumnToItem(mlw,row,column,item_ptr)
  1152. XfwfMultiListWidget mlw;
  1153. int row,column,*item_ptr;
  1154. {
  1155.     register int x_stride,y_stride;
  1156.  
  1157.     if (row < 0 || row >= MultiListNumRows(mlw) ||
  1158.         column < 0 || column >= MultiListNumCols(mlw))
  1159.     {
  1160.         return(False);
  1161.     }
  1162.     if (MultiListRowMajor(mlw))
  1163.     {
  1164.         x_stride = 1;
  1165.         y_stride = MultiListNumCols(mlw);
  1166.     }
  1167.         else
  1168.     {
  1169.         x_stride = MultiListNumRows(mlw);
  1170.         y_stride = 1;
  1171.     }
  1172.     *item_ptr = row * y_stride + column * x_stride;
  1173.     if (*item_ptr >= MultiListNumItems(mlw))
  1174.         return(False);
  1175.         else
  1176.         return(True);
  1177. } /* End RowColumnToItem */
  1178.  
  1179.  
  1180. /*---------------------------------------------------------------------------*
  1181.  
  1182.     Boolean ItemToRowColumn(mlw,item_index,row_ptr,column_ptr)
  1183.  
  1184.     This routine takes an item number <item_index> and attempts
  1185.     to convert the index into row and column numbers stored through
  1186.     <row_ptr> and <column_ptr>.  If the item number does not
  1187.     corespond to a valid item, False is returned, else True is
  1188.     returned.
  1189.  
  1190.  *---------------------------------------------------------------------------*/
  1191.  
  1192. static Boolean ItemToRowColumn(mlw,item_index,row_ptr,column_ptr)
  1193. XfwfMultiListWidget mlw;
  1194. int item_index,*row_ptr,*column_ptr;
  1195. {
  1196.     if (item_index < 0 || item_index >= MultiListNumItems(mlw))
  1197.     {
  1198.         return(False);
  1199.     }
  1200.     if (MultiListRowMajor(mlw))
  1201.     {
  1202.         *row_ptr = item_index / MultiListNumCols(mlw);
  1203.         *column_ptr = item_index % MultiListNumCols(mlw);
  1204.     }
  1205.         else
  1206.     {
  1207.         *row_ptr = item_index % MultiListNumRows(mlw);
  1208.         *column_ptr = item_index / MultiListNumRows(mlw);
  1209.     }
  1210.     return(True);
  1211. } /* End ItemToRowColumn */
  1212.  
  1213. /*===========================================================================*
  1214.  
  1215.                 E V E N T    A C T I O N    H A N D L E R S
  1216.  
  1217.  *===========================================================================*/
  1218.  
  1219. /*---------------------------------------------------------------------------*
  1220.  
  1221.     Select(mlw,event,params,num_params)
  1222.  
  1223.     This action handler is called when a user selects an item in the
  1224.     MultiList.  This action first unselects all previously selected
  1225.     items, then selects the item under the mouse, if it is not a
  1226.     background gap, and if it is sensitive.
  1227.  
  1228.     The MultiListMostRecentItem(mlw) variable will be set to the
  1229.     item clicked on, or -1 if the item is background or insensitive.
  1230.     The MultiListMostRecentAct(mlw) variable will be set to
  1231.     XfwfMultiListActionHighlight, in case the selection region is extended.
  1232.  
  1233.  *---------------------------------------------------------------------------*/
  1234.  
  1235. /* ARGSUSED */
  1236. static void Select(mlw,event,params,num_params)
  1237. XfwfMultiListWidget mlw;
  1238. XEvent *event;
  1239. String *params;
  1240. Cardinal *num_params;
  1241. {
  1242.     int click_x,click_y;
  1243.     int status,item_index,row,column;
  1244.  
  1245.     click_x = event->xbutton.x;
  1246.     click_y = event->xbutton.y;
  1247.     PixelToRowColumn(mlw,click_x,click_y,&row,&column);
  1248.     XfwfMultiListUnhighlightAll(mlw);
  1249.     MultiListMostRecentAct(mlw) = XfwfMultiListActionHighlight;
  1250.     status = RowColumnToItem(mlw,row,column,&item_index);
  1251.     if ((status == False) ||
  1252.         (!MultiListItemSensitive(MultiListNthItem(mlw,item_index))))
  1253.     {
  1254.         MultiListMostRecentItem(mlw) = -1;
  1255.     }
  1256.         else
  1257.     {
  1258.         MultiListMostRecentItem(mlw) = item_index;
  1259.         XfwfMultiListHighlightItem(mlw,item_index);
  1260.     }
  1261. } /* End Select */
  1262.  
  1263.  
  1264. /*---------------------------------------------------------------------------*
  1265.  
  1266.     Unselect(mlw,event,params,num_params)
  1267.  
  1268.     This function unselects the single text item pointed to by the
  1269.     mouse, if any.  Any remaining selected entries are left selected.
  1270.  
  1271.     The MultiListMostRecentItem(mlw) variable will be set to -1, and
  1272.     the MultiListMostRecentAct(mlw) variable will be set to
  1273.     XfwfMultiListActionUnhighlight, in case the deselection region is
  1274.     extended.
  1275.     
  1276.  *---------------------------------------------------------------------------*/
  1277.  
  1278. /* ARGSUSED */
  1279. static void Unselect(mlw,event,params,num_params)
  1280. XfwfMultiListWidget mlw;
  1281. XEvent *event;
  1282. String *params;
  1283. Cardinal *num_params;
  1284. {
  1285.     int click_x,click_y;
  1286.     int status,item_index,row,column;
  1287.  
  1288.     click_x = event->xbutton.x;
  1289.     click_y = event->xbutton.y;
  1290.     PixelToRowColumn(mlw,click_x,click_y,&row,&column);
  1291.     MultiListMostRecentItem(mlw) = -1;
  1292.     MultiListMostRecentAct(mlw) = XfwfMultiListActionUnhighlight;
  1293.     status = RowColumnToItem(mlw,row,column,&item_index);
  1294.     if ((status == True) &&
  1295.         (MultiListItemSensitive(MultiListNthItem(mlw,item_index))))
  1296.         XfwfMultiListHighlightItem(mlw,item_index);
  1297. } /* End Unselect */
  1298.  
  1299.  
  1300. /*---------------------------------------------------------------------------*
  1301.  
  1302.     Toggle(mlw,event,params,num_params)
  1303.  
  1304.     This action handler implements the toggling of selection status
  1305.     for a single item.  Any remaining selected entries are left selected.
  1306.  
  1307.     If the mouse is not over a selectable text item, the
  1308.     MultiListMostRecentAct(mlw) variable is set to
  1309.     XfwfMultiListActionHighlight, in case the region is extended into
  1310.     selectable items later.  MultiListMostRecentItem(mlw) is set to -1.
  1311.  
  1312.     If the mouse is over a selectable text item, the item highlight is
  1313.     toggled.  If the item is currently selected, it becomes deselected.
  1314.     If unselected, the item becomes selected.  At the same time, the
  1315.     MultiListMostRecentAct(mlw) variable is set to
  1316.     XfwfMultiListActionHighlight if the item was not previously selected,
  1317.     or XfwfMultiListActionUnhighlight if the item was previously selected.
  1318.     MultiListMostRecentItem(mlw) is set to the index of the item clicked
  1319.     on if the item is selected, or -1 if it is unselected.
  1320.  
  1321.  *---------------------------------------------------------------------------*/
  1322.  
  1323. /* ARGSUSED */
  1324. static void Toggle(mlw,event,params,num_params)
  1325. XfwfMultiListWidget mlw;
  1326. XEvent *event;
  1327. String *params;
  1328. Cardinal *num_params;
  1329. {
  1330.     int click_x,click_y;
  1331.     int status,item_index,row,column;
  1332.  
  1333.     click_x = event->xbutton.x;
  1334.     click_y = event->xbutton.y;
  1335.     PixelToRowColumn(mlw,click_x,click_y,&row,&column);
  1336.     status = RowColumnToItem(mlw,row,column,&item_index);
  1337.     if ((status == False) ||
  1338.         (!MultiListItemSensitive(MultiListNthItem(mlw,item_index))))
  1339.     {
  1340.         MultiListMostRecentAct(mlw) = XfwfMultiListActionHighlight;
  1341.         MultiListMostRecentItem(mlw) = -1;
  1342.     }
  1343.         else
  1344.     {
  1345.         MultiListMostRecentAct(mlw) =
  1346.             XfwfMultiListToggleItem(mlw,item_index);
  1347.         MultiListMostRecentItem(mlw) = item_index;
  1348.     }
  1349. } /* End Toggle */
  1350.  
  1351.  
  1352. /*---------------------------------------------------------------------------*
  1353.  
  1354.     Extend(mlw,event,params,num_params)
  1355.  
  1356.     This action handler implements the extension of a selection/
  1357.     deselection region.
  1358.  
  1359.     The MultiListMostRecentAct(mlw) variable is used to determine
  1360.     if items are to be selected or unselected.  This routine performs
  1361.     select or unselect actions on each item it is called on.
  1362.  
  1363.  *---------------------------------------------------------------------------*/
  1364.  
  1365. /* ARGSUSED */
  1366. static void Extend(mlw,event,params,num_params)
  1367. XfwfMultiListWidget mlw;
  1368. XEvent *event;
  1369. String *params;
  1370. Cardinal *num_params;
  1371. {
  1372.     int click_x,click_y;
  1373.     int status,item_index,row,column;
  1374.  
  1375.     click_x = ((XMotionEvent*)event)->x;
  1376.     click_y = ((XMotionEvent*)event)->y;
  1377.     PixelToRowColumn(mlw,click_x,click_y,&row,&column);
  1378.     status = RowColumnToItem(mlw,row,column,&item_index);
  1379.     if ((status == True) &&
  1380.         (MultiListItemSensitive(MultiListNthItem(mlw,item_index))))
  1381.     {
  1382.         MultiListMostRecentItem(mlw) = item_index;
  1383.         if (MultiListMostRecentAct(mlw) == XfwfMultiListActionHighlight)
  1384.             XfwfMultiListHighlightItem(mlw,item_index);
  1385.             else
  1386.             XfwfMultiListUnhighlightItem(mlw,item_index);
  1387.     }
  1388. } /* End Extend */
  1389.  
  1390.  
  1391. /*---------------------------------------------------------------------------*
  1392.  
  1393.     Notify(mlw,event,params,num_params)
  1394.  
  1395.     This function performs the Notify action, which issues a callback
  1396.     after a selection/unselection has completed.  All callbacks on the
  1397.     callback list are invoked, and a XfxfMultiListReturnStruct describing
  1398.     the selection state is returned.
  1399.  
  1400.     In addition, if the XtNpasteBuffer resource is true and at least one
  1401.     text item is selected, all the selected items are placed in the X
  1402.     cut buffer (buf(0)) separated by newlines.
  1403.  
  1404.  *---------------------------------------------------------------------------*/
  1405.  
  1406. /* ARGSUSED */
  1407. static void Notify(mlw,event,params,num_params)
  1408. XfwfMultiListWidget mlw;
  1409. XEvent *event;
  1410. String *params;
  1411. Cardinal *num_params;
  1412. {
  1413.     char *buffer;
  1414.     String string;
  1415.     int i,byte_count,item_index;
  1416.     XfwfMultiListReturnStruct ret_value;
  1417.  
  1418.     if ((MultiListNumSelected(mlw) != 0) && MultiListPaste(mlw))
  1419.     {
  1420.         byte_count = 0;
  1421.         for (i = 0; i < MultiListNumSelected(mlw); i++)
  1422.         {
  1423.             item_index = MultiListSelArray(mlw)[i];
  1424.             string = MultiListItemString(MultiListNthItem(mlw,
  1425.                 item_index));
  1426.             byte_count = byte_count + strlen(string) + 1;
  1427.         }
  1428.         buffer = (char *)XtMalloc(byte_count);
  1429.         buffer[0] = '\0';
  1430.         for (i = 0; i < MultiListNumSelected(mlw); i++)
  1431.         {
  1432.             if (i != 0) strcat(buffer,"\n");
  1433.             item_index = MultiListSelArray(mlw)[i];
  1434.             string = MultiListItemString(MultiListNthItem(mlw,
  1435.                 item_index));
  1436.             strcat(buffer,string);
  1437.         }
  1438.         XStoreBytes(XtDisplay(mlw),buffer,byte_count);
  1439.         XtFree(buffer);
  1440.     }
  1441.  
  1442.     ret_value.action = MultiListMostRecentAct(mlw);
  1443.     ret_value.item = MultiListMostRecentItem(mlw);
  1444.     if (ret_value.item == -1)
  1445.         ret_value.string = NULL;
  1446.         else
  1447.         ret_value.string = MultiListItemString(MultiListNthItem(mlw,
  1448.             ret_value.item));
  1449.     ret_value.num_selected = MultiListNumSelected(mlw);
  1450.     ret_value.selected_items = MultiListSelArray(mlw);
  1451.     XtCallCallbacks((Widget)mlw,XtNcallback,(caddr_t)&ret_value);
  1452. } /* End Notify */
  1453.  
  1454. /*===========================================================================*
  1455.  
  1456.         U S E R    C A L L A B L E    U T I L I T Y    R O U T I N E S
  1457.  
  1458.  *===========================================================================*/
  1459.  
  1460. /*---------------------------------------------------------------------------*
  1461.  
  1462.     Boolean XfwfMultiListHighlightItem(mlw,item_index)
  1463.  
  1464.     This routine selects an item with index <item_index> in the
  1465.     MultiList widget <mlw>.  If a maximum number of selections is specified
  1466.     and exceeded, the earliest selection will be unselected.  If
  1467.     <item_index> doesn't correspond to an item the most recently
  1468.     clicked item will be set to -1 and this routine will immediately
  1469.     return, otherwise the most recently clicked item will be set to the
  1470.     current item.  If the clicked on item is not sensitive, or if the
  1471.     click is not on an item, False is returned, else True is returned.
  1472.  
  1473.  *---------------------------------------------------------------------------*/
  1474.  
  1475. Boolean XfwfMultiListHighlightItem(mlw,item_index)
  1476. XfwfMultiListWidget mlw;
  1477. int item_index;
  1478. {
  1479.     XfwfMultiListItem *item;
  1480.  
  1481.     if (MultiListMaxSelectable(mlw) == 0) return(False);
  1482.     if (item_index < 0 || item_index >= MultiListNumItems(mlw))
  1483.     {
  1484.         MultiListMostRecentItem(mlw) = -1;
  1485.         return(False);
  1486.     }
  1487.     item = MultiListNthItem(mlw,item_index);
  1488.     if (MultiListItemSensitive(item) == False) return(False);
  1489.     MultiListMostRecentItem(mlw) = item_index;
  1490.     if (MultiListItemHighlighted(item) == True) return(True);
  1491.     if (MultiListNumSelected(mlw) == MultiListMaxSelectable(mlw))
  1492.     {
  1493.         XfwfMultiListUnhighlightItem(mlw,MultiListSelArray(mlw)[0]);
  1494.     }
  1495.     MultiListItemHighlighted(item) = True;
  1496.     MultiListSelArray(mlw)[MultiListNumSelected(mlw)] = item_index;
  1497.     ++ MultiListNumSelected(mlw);
  1498.     RedrawItem(mlw,item_index);
  1499.     return(True);
  1500. } /* End XfwfMultiListHighlightItem */
  1501.  
  1502.  
  1503. /*---------------------------------------------------------------------------*
  1504.  
  1505.     XfwfMultiListHighlightAll(mlw)
  1506.  
  1507.     This routine highlights all highlightable items in the MultiList
  1508.     widget <mlw>, up to the maximum number of allowed highlightable
  1509.     items;
  1510.  
  1511.  *---------------------------------------------------------------------------*/
  1512.  
  1513. void XfwfMultiListHighlightAll(mlw)
  1514. XfwfMultiListWidget mlw;
  1515. {
  1516.     int i;
  1517.     XfwfMultiListItem *item;
  1518.  
  1519.     MultiListNumSelected(mlw) = 0;
  1520.     for (i = 0; i < MultiListNumItems(mlw); i++)
  1521.     {
  1522.         item = MultiListNthItem(mlw,i);
  1523.         MultiListItemHighlighted(item) = False;
  1524.     }
  1525.     for (i = 0; i < MultiListNumItems(mlw); i++)
  1526.     {
  1527.         if (MultiListNumSelected(mlw) == MultiListMaxSelectable(mlw))
  1528.             break;
  1529.         item = MultiListNthItem(mlw,i);
  1530.         if (MultiListItemSensitive(item) == False) continue;
  1531.         MultiListItemHighlighted(item) = True;
  1532.         MultiListSelArray(mlw)[MultiListNumSelected(mlw)] = i;
  1533.         ++ MultiListNumSelected(mlw);
  1534.     }
  1535.     RedrawAll(mlw);
  1536. } /* End XfwfMultiListHighlightAll */
  1537.  
  1538.  
  1539. /*---------------------------------------------------------------------------*
  1540.  
  1541.     XfwfMultiListUnhighlightItem(mlw,item_index)
  1542.  
  1543.     This routine unselects the item with index <item_index> in the
  1544.     MultiList widget <mlw>.  If <item_index> doesn't correspond to a
  1545.     selected item, then nothing will happen.  Otherwise, the item
  1546.     is unselected and the selection array and count are updated.
  1547.  
  1548.  *---------------------------------------------------------------------------*/
  1549.  
  1550. void XfwfMultiListUnhighlightItem(mlw,item_index)
  1551. XfwfMultiListWidget mlw;
  1552. int item_index;
  1553. {
  1554.     int i;
  1555.     XfwfMultiListItem *item;
  1556.  
  1557.     if (MultiListMaxSelectable(mlw) == 0) return;
  1558.     if (item_index < 0 || item_index >= MultiListNumItems(mlw)) return;
  1559.     item = MultiListNthItem(mlw,item_index);
  1560.     if (MultiListItemHighlighted(item) == False) return;
  1561.     MultiListItemHighlighted(item) = False;
  1562.  
  1563.     for (i = 0; i < MultiListNumSelected(mlw); i++)
  1564.         if (MultiListSelArray(mlw)[i] == item_index) break;
  1565.     for (i = i + 1; i < MultiListNumSelected(mlw); i++)
  1566.         MultiListSelArray(mlw)[i - 1] = MultiListSelArray(mlw)[i];
  1567.     -- MultiListNumSelected(mlw);
  1568.  
  1569.     RedrawItem(mlw,item_index);
  1570. } /* End XfwfMultiListUnhighlightItem */
  1571.  
  1572.  
  1573. /*---------------------------------------------------------------------------*
  1574.  
  1575.     XfwfMultiListUnhighlightAll(mlw)
  1576.  
  1577.     This routine unhighlights all items in the MultiList widget <mlw>.
  1578.  
  1579.  *---------------------------------------------------------------------------*/
  1580.  
  1581. void XfwfMultiListUnhighlightAll(mlw)
  1582. XfwfMultiListWidget mlw;
  1583. {
  1584.     int i;
  1585.     XfwfMultiListItem *item;
  1586.  
  1587.     for (i = 0; i < MultiListNumItems(mlw); i++)
  1588.     {                
  1589. #ifdef DEBUG
  1590.   showf("=M= pos 1 %d", i);
  1591. #endif
  1592.         item = MultiListNthItem(mlw,i);
  1593.         if (MultiListItemHighlighted(item))
  1594.             {XfwfMultiListUnhighlightItem(mlw,i); 
  1595. #ifdef DEBUG
  1596. showf("=M= pos 2 %d", i);
  1597. #endif
  1598. }
  1599.     }
  1600. #ifdef DEBUG
  1601.     show("=M= pos 3");
  1602. #endif
  1603.     MultiListNumSelected(mlw) = 0;     
  1604. #ifdef DEBUG
  1605. show("=M= pos 4");
  1606. #endif
  1607. } /* End XfwfMultiListUnhighlightAll */
  1608.  
  1609.  
  1610. /*---------------------------------------------------------------------------*
  1611.  
  1612.     int XfwfMultiListToggleItem(mlw,item_index)
  1613.  
  1614.     This routine highlights the item with index <item_index>
  1615.     if it is unhighlighted and unhighlights it if it is already
  1616.     highlighted.  The action performed by the toggle is returned
  1617.     (XfwfMultiListActionHighlight or XfwfMultiListActionUnhighlight).
  1618.  
  1619.  *---------------------------------------------------------------------------*/
  1620.  
  1621. int XfwfMultiListToggleItem(mlw,item_index)
  1622. XfwfMultiListWidget mlw;
  1623. int item_index;
  1624. {
  1625.     XfwfMultiListItem *item;
  1626.  
  1627.     if (MultiListMaxSelectable(mlw) == 0)
  1628.         return(XfwfMultiListActionNothing);
  1629.     if (item_index < 0 || item_index >= MultiListNumItems(mlw))
  1630.         return(XfwfMultiListActionNothing);
  1631.     item = MultiListNthItem(mlw,item_index);
  1632.     if (MultiListItemSensitive(item) == False)
  1633.         return(XfwfMultiListActionNothing);
  1634.     if (MultiListItemHighlighted(item))
  1635.     {
  1636.         XfwfMultiListUnhighlightItem(mlw,item_index);
  1637.         return(XfwfMultiListActionUnhighlight);
  1638.     }
  1639.         else
  1640.     {
  1641.         XfwfMultiListHighlightItem(mlw,item_index);
  1642.         return(XfwfMultiListActionHighlight);
  1643.     }
  1644. } /* End XfwfMultiListToggleItem */
  1645.  
  1646.  
  1647. /*---------------------------------------------------------------------------*
  1648.  
  1649.     XfwfMultiListReturnStruct *XfwfMultiListGetHighlighted(mlw)
  1650.  
  1651.     This routine takes a MultiList widget <mlw> and returns a
  1652.     XfwfMultiListReturnStruct whose num_selected and selected_items
  1653.     fields contain the highlight information.  The action field
  1654.     is set to MULTILIST_ACTION_STATUS, and the item_index and string
  1655.     fields are invalid.
  1656.  
  1657.  *---------------------------------------------------------------------------*/
  1658.  
  1659. XfwfMultiListReturnStruct *XfwfMultiListGetHighlighted(mlw)
  1660. XfwfMultiListWidget mlw;
  1661. {
  1662.     XfwfMultiListItem *item;
  1663.     static XfwfMultiListReturnStruct ret_value;
  1664.  
  1665.     ret_value.action = XfwfMultiListActionStatus;
  1666.     if (MultiListNumSelected(mlw) == 0)
  1667.     {
  1668.         ret_value.item = -1;
  1669.         ret_value.string = NULL;
  1670.     }
  1671.         else
  1672.     {
  1673.         ret_value.item = MultiListSelArray(mlw)
  1674.             [MultiListNumSelected(mlw) - 1];
  1675.         item = MultiListNthItem(mlw,ret_value.item);
  1676.         ret_value.string = MultiListItemString(item);
  1677.     }
  1678.     ret_value.num_selected = MultiListNumSelected(mlw);
  1679.     ret_value.selected_items = MultiListSelArray(mlw);
  1680.     return(&ret_value);
  1681. } /* End XfwfMultiListGetHighlighted */
  1682.  
  1683.  
  1684. /*---------------------------------------------------------------------------*
  1685.  
  1686.     Boolean XfwfMultiListIsHighlighted(mlw,item_index)
  1687.  
  1688.     This routine checks if the item with index <item_index>
  1689.     is highlighted and returns True or False depending.  If
  1690.     <item_index> is invalid, False is returned.
  1691.  
  1692.  *---------------------------------------------------------------------------*/
  1693.  
  1694. Boolean XfwfMultiListIsHighlighted(mlw,item_index)
  1695. XfwfMultiListWidget mlw;
  1696. int item_index;
  1697. {
  1698.     XfwfMultiListItem *item;
  1699.  
  1700.     if (item_index < 0 || item_index >= MultiListNumItems(mlw))
  1701.         return(False);
  1702.     item = MultiListNthItem(mlw,item_index);
  1703.     return(MultiListItemHighlighted(item));
  1704. } /* End XfwfMultiListIsHighlighted */
  1705.  
  1706.  
  1707. /*---------------------------------------------------------------------------*
  1708.  
  1709.     Boolean XfwfMultiListGetItemInfo(mlw,item_index,str_ptr,h_ptr,s_ptr)
  1710.  
  1711.     This routine returns the string, highlight status and
  1712.     sensitivity information for the item with index <item_index>
  1713.     via the pointers <str_ptr>, <h_ptr> and <s_ptr>.  If the item
  1714.     index is invalid, False is returned, else True is returned.
  1715.  
  1716.  *---------------------------------------------------------------------------*/
  1717.  
  1718. Boolean XfwfMultiListGetItemInfo(mlw,item_index,str_ptr,h_ptr,s_ptr)
  1719. XfwfMultiListWidget mlw;
  1720. int item_index;
  1721. String *str_ptr;
  1722. Boolean *h_ptr,*s_ptr;
  1723. {
  1724.     XfwfMultiListItem *item;
  1725.  
  1726.     if (item_index < 0 || item_index >= MultiListNumItems(mlw))
  1727.         return(False);
  1728.     item = MultiListNthItem(mlw,item_index);
  1729.     *str_ptr = MultiListItemString(item);
  1730.     *h_ptr = MultiListItemHighlighted(item);
  1731.     *s_ptr = MultiListItemSensitive(item);
  1732.     return(True);
  1733. } /* End XfwfMultiListGetItemInfo */
  1734.  
  1735.  
  1736. /*---------------------------------------------------------------------------*
  1737.  
  1738.     XfwfMultiListSetNewData(mlw,list,nitems,longest,resize,
  1739.         sensitivity_array)
  1740.  
  1741.     This routine will set a new set of strings <list> into the
  1742.     MultiList widget <mlw>.  If <resize> is True, the MultiList widget will
  1743.     try to resize itself.
  1744.  
  1745.  *---------------------------------------------------------------------------*/
  1746.  
  1747. #if NeedFunctionPrototypes
  1748. void
  1749. XfwfMultiListSetNewData(XfwfMultiListWidget mlw, String *list,
  1750.             int nitems, int longest, int resize,
  1751.             Boolean *sensitivity_array)
  1752. #else
  1753. void
  1754. XfwfMultiListSetNewData(mlw,list,nitems,longest,resize,sensitivity_array)
  1755. XfwfMultiListWidget mlw;
  1756. String *list;
  1757. int nitems,longest;
  1758. int resize;
  1759. Boolean *sensitivity_array;
  1760. #endif
  1761. {
  1762.     DestroyOldData(mlw);
  1763.     MultiListList(mlw) = list;
  1764.     MultiListNumItems(mlw) = max(nitems,0);
  1765.     MultiListLongest(mlw) = max(longest,0);
  1766.     MultiListSensitiveArray(mlw) = sensitivity_array;
  1767.     InitializeNewData(mlw);
  1768.     RecalcCoords(mlw,resize,resize);
  1769.     if (XtIsRealized((Widget)mlw)) Redisplay(mlw,NULL,NULL);
  1770. } /* End XfwfMultiListSetNewData */
  1771.